package com.fingard.dsp.bank.directbank.xwbank02;

import java.io.File;
import java.lang.reflect.Field;
import java.util.Iterator;
import java.util.Map;

import org.apache.commons.collections.map.LinkedMap;

import com.alibaba.fastjson.JSON;
import com.fingard.FGBiz;
import com.fingard.dsp.bank.directbank.DirectBase;

public class XWBank02Base extends DirectBase {
	public String getCharset() {
		return getBankConfig().getCharset("UTF-8");
	}

	public String getConfigPath(String tmpPath) {
		return tmpPath.replace("{$DSPHOME}", FGBiz.DSPHOME);
	}
	
	public void writeBankLogStep2(Object obj) throws Exception {
		LinkedMap mapParams = new LinkedMap();

		Class<? extends Object> cls = obj.getClass();
		Field[] fields = cls.getDeclaredFields();
		for (int i = 0; i < fields.length; i++) {
			Field f = fields[i];
			f.setAccessible(true);
			mapParams.put(f.getName(), (String) f.get(obj));
		}
		String sbLog = JSON.toJSONString(mapParams);
		WriteBankLogStep2(sbLog);
	}

	public void writeBankLogStep3(Map<String, Object> p_map) {
		StringBuilder sbLog = new StringBuilder();

		Iterator<String> iter = p_map.keySet().iterator();
		while (iter.hasNext()) {
			String eachKey = iter.next();
			sbLog.append(eachKey).append(":").append(p_map.get(eachKey)).append("\r\n");
		}
		WriteBankLogStep3(sbLog);
	}

	public String createLocalFilePath(String p_dir) {
        File mdDir = new File(p_dir);
        if (!mdDir.exists()) {
            mdDir.mkdirs();
        }
        return p_dir;
    }
}
